<template>
  <div id="app" style="height:100%">
    <!-- <loading v-model="isLoading"></loading> -->
    <view-box style="height:100%">
      <transition name="slide-fade">
        <router-view></router-view>
      </transition>
      <the-main-menu/>
    </view-box>
  </div>
</template>

<script>
import {
  ViewBox,
  Loading
  } from 'vux'
// import { mapState } from 'vuex'
// 底部导航栏
import TheMainMenu from './components/commons/TheMainMenu'
// import CryptoJS from 'crypto-js'
// import {getAES, getDAes} from './components/commons/cryptoUtils.js'
import { mapActions } from 'vuex'

// const TheMainMenu = () => import('./components/commons/TheMainMenu')

export default {
  name: 'app',
  components: {
    TheMainMenu,
    ViewBox,
    Loading
  },
  data () {
    return {
      isLoading: false
    }
  },
  computed: {
    // ...mapState({
    //   isLoading: function () {
    //     return this.$store.state.isLoading
    //   }
    // })
  },
  methods: {
    ...mapActions([])
  },
  created () {
    // 开始
    // this.sysInit()

    console.log('润皓备考2.0')
    // 清除历史记录
    this.deleteExpiryHistory()
    this.deleteLimitedHistory()

    // 保存用户的openId,OpenId在URL:http://domain/profix/#/?openid=XXXXXXXXXXXXXXXXXXXXX&_t_t_t=23764387568346583468
    console.log('发起地址：' + window.location.hash)
    var array1 = window.location.hash.split('openId')
    console.log('URL是否包含Openid，数组大小，大于1就包含：' + array1.length)

    if (array1.length > 1) {
      var array2 = array1[1].split('&')
      console.log('去掉&符号')
      console.log(array2)
      var array3 = array2[0].split('=')
      console.log('去掉=号')
      console.log(array3)
      var myopenid = array3[1]
      console.log('openid为：' + myopenid)
      this.$store.commit('updateOpenId', {openId: myopenid})
      this.$http.get(this.$store.state.vxPersonalIsBind + '?openId=' + myopenid).then((res) => {
        console.log(res)
        if (res.data.code === 1) {
          this.$http.get(this.$store.state.vxPersonalBind + '?openId=' + myopenid).then((res) => {
            console.log(res)
            if (res.data.code === 1) {
              this.$vux.alert.show({
                title: '警告',
                content: '因为您的微信昵称包含特殊字符，请您更改昵称再次登录系统。'
              })
            } else {
              console.log('用户绑定成功')
            }
          })
        } else {
          console.log('用户已经绑定')
        }
      })
    } else {
      this.$vux.alert.show({
        title: '警告',
        content: '页面刷新可能导致数据异常，请关闭窗口再次打开系统。'
      })
    }
    // 本微信是否已经有用户登录，如果没有则记录openid，如果有查看是否为同一账户登录，如果不是同一账户登录，则清空本地缓存
    if (localStorage.hasOwnProperty('openId')) {
      var oldOpenId = localStorage.getItem('openId')
      if (myopenid !== oldOpenId) {
        localStorage.clear()
      }
    } else {
      localStorage.setItem('openId', myopenid)
    }
    // console.log(this.$store.state.openId)
    // var key = 'ouUCM07mEvukJ5podnS5igoIYXCQ'
    // var testString = 'hello world'
    // console.log('加密前:' + testString)
    // var aesString = getAES(testString, key)
    // console.log('加密后：' + aesString)
    // var unAesString = getDAes(aesString, key)
    // console.log('解密后:' + unAesString)
  }
}
</script>

<style lang="less">
@import '~vux/src/styles/reset.less';

html, body {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: #fbf9fe;
  height: 100%;
  width: 100%;
  overflow-x: hidden;
}


.fade-enter-active, .fade-leave-active {
  transition: opacity .5s
}
.fade-enter, .fade-leave-to{
  opacity: 0
}

/**
.slide-fade-enter-active {
  transition: all .3s ease;
}
.slide-fade-leave-active {
  transition: all .8s cubic-bezier(1.0, 0.5, 0.8, 1.0);
}
.slide-fade-enter, .slide-fade-leave-active {
  padding-left: 10px;
  opacity: 0;
}
**/
</style>
